#include "systemfile.h"
#include <QString>
#include <stdio.h>
#include <QDataStream>
#include <QDebug>
#include <QMap>
systemFile::systemFile()
{
    //读取MAC地址
    QNetworkInterface  localInterface =localInterface.interfaceFromName("eth0");
    this->mac =localInterface.hardwareAddress();
    this->readInterfaces();


}
//读取网络设置
bool systemFile::readInterfaces()
{
    QFile interfaces("/etc/network/interfaces");
    QByteArray buffer;
    QString str;
    QStringList strList;
    QMap<QString,QString> map;
    //red interfaces
    interfaces.open(QIODevice::ReadOnly);
     while(1)
    {
        buffer = interfaces.readLine();
        if(buffer.length() == 0)
        {
            break;
        }
        str = QString(buffer);
        strList = str.split(" ");
        if(strList.count() >=2)
        {
            map.insert(strList[0],strList[1]);
        }
    }
    interfaces.close();
    this->localIp = map["address"].trimmed();
    this->gatewayIp = map["gateway"].trimmed();
    this->mask = map["netmask"].trimmed();
    /*qDebug() << "Ip:"<< this->localIp;
    qDebug() << "gateway:"<< this->gatewayIp;
    qDebug() << "mask:" << this->mask;*/
    return true;
}
